package ioStream.file.nodeStream.byteStream;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA
 * Description:文件拷贝学习
 * User:22954
 * Date:2024-03-15
 * Time:15:44
 */
@SuppressWarnings("all")
public class FileCopy {
    public static void main(String[] args) {
        String srcFilePath = "c:\\Users\\22954\\Music\\朴树 - 猎户星座_hires.flac";
        String desFilePath = "f:/Test/朴树 - 猎户星座_hires.flac";
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        byte[] buf = new byte[1024];
        int readlen = 0;
        try {
            fileOutputStream = new FileOutputStream(desFilePath);
            fileInputStream = new FileInputStream(srcFilePath);
            while ((readlen = fileInputStream.read(buf)) != -1) {
                fileOutputStream.write(buf, 0, readlen);//不用write(byte[])防止文件损坏----多拷贝部分数据
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                if (fileInputStream != null) fileInputStream.close();
                if (fileOutputStream != null) fileOutputStream.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
